(function(){
	angular.module("webApp").controller("AccountCtrl",AccountCtrl);
	AccountCtrl.$inject=['$scope','dataService','helper','$state','$location'];
	function AccountCtrl($scope,dataService,helper,$state,$location){
		$scope.listAction=function(){
			$scope.page_Size=10;
			$scope.getaccountList(1);
		}
		$scope.getaccountList=function(page_No){
			var query={page_no:page_No,page_size:$scope.page_Size};
			dataService.accountGet(query).then(function(result){
				if(result.Msg){
					helper.myAlert("error:"+result.Msg);
				}else{
					$scope.accounts=result.shop;
					$scope.accountsTotal=result.total_count;
					// helper.myAlert("success",null,null,function(){
					// 	$state.go("fenxiaograde.list");
					// });
				}
			});
		}
		$scope.infoAciton=function(){
			var member_id=$location.search().member_id;
			dataService.accountOne(member_id).then(function(result){
				$scope.account=result;
			});
		}
		
		$scope.addAction=function(){
			$scope.member_id=$location.search().member_id;
			if($scope.member_id){
				dataService.accountOne($scope.member_id).then(function(result){
					if(result.Msg){
						helper.myAlert("error:"+result.Msg);
					}else{
						$scope.account=result;
					}
				});
			}else{
				$scope.account={};
				$scope.account.integral=0;
				$scope.account.balance=0;

				$scope.account.freezesFee=0;
				$scope.account.presentBalance=0;
				$scope.account.flowBalance=0;
				$scope.account.growAmount=0;
				$scope.account.freezesPresent=0;
				$scope.account.totalPresentFee=0;
				$scope.account.totalFee=0;
				$scope.account.totalCharge=0;
				$scope.account.totalPay=0;
			}
		}
		$scope.AccountAdd=function(){
			if($scope.account.member_id){

			}else{
				dataService.accountAdd($scope.account).then(function(result){
					if(result.Msg){
						helper.myAlert("error:"+result.Msg);
					}else{
						helper.myAlert("success",null,null,function(){
							$state.go("account.list");
						});
					}
				});
			}
		}
	}
})();